export default {
  imgerror: {
    inserted(dom, obj) {
      dom.src = dom.src || obj.value
      dom.onerror = function() {
        dom.src = obj.value
      }
    },
    componentUpdated(dom, obj) {
      dom.src = dom.src || obj.value
    },
    unbind(dom) {
      dom.onerror = null
    }
  },
  clickoutside: {
    inserted(dom, obj, vnode) {
      const fn = (e) => {
        if (!dom.contains(e.target)) {
          const fn = obj.value
          fn()
        }
      }
      vnode.fn = fn
      document.addEventListener('click', vnode.fn)
    },
    unbind(dom, obj, vnode) {
      document.removeEventListener('click', vnode.fn)
    }
  }
}
